﻿using System.Collections.Generic;
using Yuebon.CMS.Dtos;
using Yuebon.CMS.IServices;
using Yuebon.CMS.Models;
using Yuebon.Commons;
using Yuebon.Commons.IoC;
using Yuebon.Commons.Models;

namespace Yuebon.CMS.Application
{
    public class PageNewsApp
    {
        IPageNewsService pagenewsservice = IoCContainer.Resolve<IPageNewsService>();
        IPageCategoryService pageCategoryService = IoCContainer.Resolve<IPageCategoryService>();

        /// <summary>
        /// 根据条件查询数据库,并返回对象集合(用于分页数据显示)
        /// </summary>
        /// <param name="condition">查询的条件</param>
        /// <param name="info">分页实体</param>
        /// <param name="fieldToSort">排序字段</param>
        /// <param name="desc">是否降序</param>
        /// <returns>指定对象的集合</returns>
        public List<PageNewsDto> FindWithPager(string where, PagerInfo pagerInfo, string fieldToSort, bool desc)
        {
            List<PageNews> list= pagenewsservice.FindWithPager(where, pagerInfo, fieldToSort, desc);
            List<PageNewsDto> resultList = new List<PageNewsDto>();
            foreach(PageNews item in list)
            {
                PageNewsDto pageNewsDto = new PageNewsDto();
                pageNewsDto.Id = item.Id;
                pageNewsDto.ImgUrl = item.ImgUrl;
                pageNewsDto.IsHot = item.IsHot;
                pageNewsDto.IsMsg = item.IsMsg;
                pageNewsDto.IsRed = item.IsRed;
                pageNewsDto.IsSlide = item.IsSlide;
                pageNewsDto.IsSys = item.IsSys;
                pageNewsDto.IsTop = item.IsTop;
                pageNewsDto.Author = item.Author;
                pageNewsDto.CategoryId = item.CategoryId;
                pageNewsDto.CategoryName = pageCategoryService.Get(item.CategoryId).Title;
                pageNewsDto.Click = item.Click;
                pageNewsDto.CompanyId = item.CompanyId;
                pageNewsDto.CreatorTime = item.CreatorTime;
                pageNewsDto.CreatorUserId = item.CreatorUserId;
                pageNewsDto.DeleteMark = item.DeleteMark;
                pageNewsDto.DeleteTime = item.DeleteTime;
                pageNewsDto.DeleteUserId = item.DeleteUserId;
                pageNewsDto.DeptId = item.DeptId;
                pageNewsDto.Description = item.Description;
                pageNewsDto.EnabledMark = item.EnabledMark;
                pageNewsDto.LastModifyTime = item.LastModifyTime;
                pageNewsDto.LastModifyUserId = item.LastModifyUserId;
                pageNewsDto.LikeCount = item.LikeCount;
                pageNewsDto.LinkUrl = item.LinkUrl;
                pageNewsDto.SeoDescription = item.SeoDescription;
                pageNewsDto.SeoKeywords = item.SeoKeywords;
                pageNewsDto.SeoTitle = item.SeoTitle;
                pageNewsDto.SortCode = item.SortCode;
                pageNewsDto.Source = item.Source;
                pageNewsDto.SubTitle = item.SubTitle;
                pageNewsDto.Tags = item.Tags;
                pageNewsDto.Title = item.Title;
                pageNewsDto.Zhaiyao = item.Zhaiyao;

                resultList.Add(pageNewsDto);
            }
            return resultList;
        }
    }
}
